package com.jason.um.utils;

import com.jason.um.user.model.UserModel;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpSession;
/**
 * @Author Jason
 * @Description TODO
 * @Date 2018/12/28
 **/
@Component
public class SpringSessionManager {

    /**
     * @Author Jason
     * @Description TODO
     * @Date 2018/12/28 16:44
     * @Param []
     * @return javax.servlet.http.HttpSession
     **/
    public HttpSession getHttpSession(){
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest().getSession();
    }

    public UserModel getLoginInfo() {
        return (UserModel)this.getHttpSession().getAttribute("LOGIN_INFO");
    }
    public void saveLoginInfo(UserModel userModel) {
        this.getHttpSession().setAttribute("LOGIN_INFO", userModel);
    }
}
